<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>思途CMS3.0</title>
    {template 'stourtravel/public/public_js'}
    {php echo Common::getCss('style.css,base.css,base2.css,plist.css,base_new.css'); }

</head>
<body style="overflow:hidden">
<table class="content-tab">
    <tr>
        <td width="119px" class="content-lt-td" valign="top">
            {template 'stourtravel/public/leftnav'}
            <!--右侧内容区-->
        </td>
        <td valign="top" class="content-rt-td" style="overflow:hidden">
        	<div class="cfg-header-bar">
        		<a href="javascript:;" class="fr btn btn-primary radius mt-6 mr-10" onclick="window.location.reload()">刷新</a>
        	</div>
            
            <div id="line_grid_panel" class="content-nrt">
                <div id="product_grid_panel" class="content-nrt">
                </div>
                <div class="panel_bar">
                    <a class="btn btn-primary radius mt-10" href="javascript:;" onClick="chooseAll()">全选</a>
                    <a class="btn btn-primary radius mt-10 ml-10" href="javascript:;" onClick="chooseDiff()">反选</a>
                    <a class="btn btn-primary radius mt-10 ml-10" href="javascript:;" onClick="delattr()">删除</a>
                </div>
        </td>
    </tr>
</table>
<script>


Ext.onReady(
    function () {
        Ext.tip.QuickTipManager.init();
        window.attr_store = Ext.create('Ext.data.Store', {
            fields: [
                'id',
                'title',
                'membernum',
                'description'
            ],
            proxy: {
                type: 'ajax',
                api: {
                    read: SITEURL+'fenxiao/admin/product/group/action/read/typeid/{$typeid}',  //读取数据的URL
                    update:  SITEURL+'fenxiao/admin/product/group/action/save/typeid/{$typeid}',
                    destroy:  SITEURL+'fenxiao/admin/product/group/action/delete/typeid/{$typeid}'
                },
                reader:{
                    type: 'json',   //获取数据的格式
                    root: 'lists',
                    totalProperty: 'total'
                }
            },
            autoLoad: true,
            listeners: {
                load:function( store, records, successful, eOpts )
                {

                    if(!successful){
                        ST.Util.showMsg("{__('norightmsg')}",5,1000);
                    }


                }
            }

        });

        //属性树
        window.attr_gridpanel = Ext.create('Ext.grid.Panel', {
            store:attr_store,
            renderTo:'product_grid_panel',
            border:0,
            bodyBorder:0,
            bodyStyle:'border-width:0px',
            scroll:'vertical', //只要垂直滚动条
            columns: [
                {
                    text: '分组名称'+ST.Util.getGridHelp('fenxiao_group_name'),
                    dataIndex: 'title',
                    id: 'attr_name',
                    sortable:false,
                    menuDisabled:true,
                    width: '25%',
                    renderer : function(value, metadata,record) {
                        return value;
                    }
                },
                {
                    text: '分销商数量',
                    dataIndex: 'membernum',
                    //  tdCls:'attr-al-mid',
                    width: '20%',
                    draggable: false,
                    sortable:false,
                    align:'center',
                    menuDisabled:true,
                    renderer : function(value, metadata,record) {
                        return value;
                    }

                }
                ,
                {
                    text:'描述',
                    dataIndex:'description',
                    width:'35%',
                    draggable:false,
                    sortable:false,
                    align:'center',
                    menuDisabled:true,
                    renderer:function(value, metadata,record){
                        return value;
                    }

                }
                ,
                {
                    text: '设置分组佣金'+ST.Util.getGridHelp('fenxiao_group_money'),
                    width: '20%',
                    tdCls: 'attr-al-mid',
                    align:'center',
                    menuDisabled:true,
                    renderer : function(value, metadata,record) {
                        var id=record.get('id');
                        return '<a href="javascript:void(0);" title="编辑" class="btn-link" onclick="goModify('+id+')">马上设置</a>';
                    }
              }
            ],
            listeners:{
                boxready:function()
                {
                    var height=Ext.dom.Element.getViewportHeight();
                    this.maxHeight=height-106;
                    this.doLayout();
                },
                afterlayout:function(grid)
                {


                    var data_height=0;
                    try{
                        data_height=grid.getView().getEl().down('.x-grid-table').getHeight();
                    }catch(e)
                    {

                    }
                    var height=Ext.dom.Element.getViewportHeight();
                    // console.log(data_height+'---'+height);
                    if(data_height>height-106)
                    {
                        window.has_biged=true;
                        grid.height=height-106;
                    }
                    else if(data_height<height-106)
                    {
                        if(window.has_biged)
                        {
                            //delete window.product_grid.height;
                            window.has_biged=false;
                            grid.doLayout();
                        }
                    }
                }
            }
        });


    }
);




Ext.EventManager.onWindowResize(function () {
    var height = Ext.dom.Element.getViewportHeight();
    var data_height = window.attr_gridpanel.getView().getEl().down('.x-grid-table').getHeight();
    if (data_height > height - 100)
        window.attr_gridpanel.height = (height - 100);
    else
        delete window.attr_gridpanel.height;
    window.attr_gridpanel.doLayout();
})

function viewScroll(extdom)   //在treeview里滚动
{
    var tree_view = window.attr_gridpanel.getView();
    var view_y = tree_view.getY();
    var dom_y = extdom.getY();
    window.setTimeout(function () {
        window.first_scroll = true;
        extdom.scrollIntoView(tree_view.getEl());
    }, 450);
}

function chooseAll() {
    var check_cmp = Ext.query('.attr_check');
    for (var i in check_cmp) {
        if (!Ext.get(check_cmp[i]).getAttribute('checked'))
            check_cmp[i].click();
    }

    //  window.sel_model.selectAll();
}
function chooseDiff() {
    var check_cmp = Ext.query('.attr_check');
    for (var i in check_cmp)
        check_cmp[i].click();
    //var records=window.sel_model.getSelection();
    //window.sel_model.selectAll(true);

    //	window.sel_model.deselect(records,true);

    //var
}

function stopDef(e)
{
    if (e && e.stopPropagation)
    //因此它支持W3C的stopPropagation()方法
        e.stopPropagation();
    else
    //否则，我们需要使用IE的方式来取消事件冒泡
        window.event.cancelBubble = true;
}

function goModify(id)
{

    var record=window.attr_store.getById(id.toString());
    var title='';
    title = id==0?'默认分组':record.get('title');
    var url = SITEURL+'fenxiao/admin/product/reward/{if isset($_GET['menuid'])}menuid/{$_GET['menuid']}/{/if}groupid/'+id;
    parent.window.addTab('设置分组全局佣金：'+title,url,1);
}


</script>
</body>
</html>
